import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const request = axios.create({
  baseURL: 'http://localhost:4000', // api 的 base_url
  timeout: 10000 // 请求超时时间
})
// 请求拦截
request.interceptors.request.use(config => {
  NProgress.start()
  const token = sessionStorage.getItem('token')
  config.headers.Authorization = 'Bearer ' + token
  return config
},
error => ({ status: 0, msg: error.message })
)
// 响应拦截
request.interceptors.response.use(response => {
  NProgress.done()
  return Promise.resolve(response)
},
error => {
  return Promise.reject(error)
}
)
export default request
